package com.demo.javase.day81;

/**
 * @Author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @date: 2025-05-09 16:05
 */
public class Test {
    public static void main(String[] args) {
        Counter counter = new Counter();
        Thread[] threads = new Thread[100];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < 100; j++) {
                    counter.increment();
                }
            });
            threads[i].start();
        }

        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        int expectedCount = 100 * 100; // 100 threads, each incrementing 100 times
        if (counter.getCount() == expectedCount) {
            System.out.println("Test passed: The count is correct. Expected " + expectedCount + ", got " + counter.getCount());
        } else {
            System.out.println("Test failed: The count is incorrect. Expected " + expectedCount + ", got " + counter.getCount());
        }
    }
}
